package com.thirteenClassics.convert;

import java.time.LocalDateTime;

import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import com.thirteenClassics.context.BaseContext;
import com.thirteenClassics.dto.EntryDTO;
import com.thirteenClassics.entity.Sentence;

@Mapper
public interface SentenceConvertMapper {
    SentenceConvertMapper INSTANCE = Mappers.getMapper(SentenceConvertMapper.class);

    @Mapping(target = "banben", source = "banben")
    @Mapping(source = "dzSentence", target = "sentenceDz")
    @Mapping(source = "picUrl", target = "imgUrl")
    @Mapping(source = "sentence2", target = "sentence2")
    @Mapping(source = "paragraphIds", target = "paragraphIds")
    @Mapping(source = "manwengLd", target = "manwengLd")
    Sentence entryDtoToSentence(EntryDTO entryDto);

    default Sentence entryDtoToSentenceWithDefaults(EntryDTO entryDto, String userName) {
        Sentence sentence = entryDtoToSentence(entryDto);
        sentence.setBookOperator(userName);
        sentence.setBookOptime(LocalDateTime.now());
        return sentence;
    }

    default Long mapBaseContextId() {
        return BaseContext.getCurrentId();
    }

    default String mapCurrentTime() {
        return LocalDateTime.now().toString();
    }
}

